\section{\TikZ\ (Part 2)}

In the previous video, we talked about drawing lines, shapes, and nodes. In this video, we are going to explore the options that are available with these commands.

Let's go back to the \texttt{fill=white} command from the last video. This is a general command that can be applied not just to nodes, but to all the drawn shapes.

\begin{center}
  \fbox{\includegraphics[width=0.85\linewidth]{img-11-1}}
\end{center}

We'll first talk about the colors. There are 19 predefined colors. I rarely go outside of the primary, secondary, and grayscale named colors. But there are a few other colors that you might find a reason to use.

\begin{center}
  \fbox{\includegraphics[width=0.85\linewidth]{img-11-2}}
\end{center}

If that's not good enough for you, you can also create your own colors. You can specify them with rgb code with the values ranging from 0 to 255. If you use a particular color often, you can actually define a color name in the preamble. Once the color is defined, you can call it the same way you call the predefined colors.

You can also describe colors as the mixture of two colors. The notation for color mixing is to have two colors with a number from 0 to 100 between them, and exclamation points as separators. The number represents the percentage of the first color, and the rest of mixture comes from the second color. I usually do this with a color and either white or black to make lighter or darker versions of the same color.

\begin{center}
  \fbox{\includegraphics[width=0.85\linewidth]{img-11-3}}
\end{center}

These colors can be used for both lines and for coloring in regions. You can see in this image that there is no black line connecting the last point to the first point. If your figure is not closed, the \texttt{fill} command will automatically connect your last point with your first point for the purposes of shading, but it will not draw that line for you.

To change the color of the line, just add the color by itself as another optional parameter. This can be applied to any line, even without a color fill. This is also how you would hide the outline of the shape. Just define the line color to be the same as the fill color. \TikZ\ is usually able to shade the inside and outside properly, but I've never really tried to push it to see how good it is. If you have a complex shading job, it's probably better to work in smaller pieces so you have better control.

There are other ways to modify the appearance of lines.
\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-11-4}}
\end{center}
\begin{itemize}
    \item To control the line width, you have a number of predefined widths or you can manually specify the \texttt{line width} as a measurement. The column of values on the right gives the actual measurements for the predefined widths. \\
    \begin{center}
      \fbox{\includegraphics[width=0.95\linewidth]{img-11-5}}
    \end{center}
    \item You also have a variety of predefined line styles. You can also create custom patterns using \texttt{dash pattern} and stating the distances that you want the pen \texttt{on} and \texttt{off}. Dots are created using \verb|\pgflinewidth|. \\
    \begin{center}
      \fbox{\includegraphics[width=0.95\linewidth]{img-11-6}}
    \end{center}
    \item You can also specify whether you want arrow tips on the ends of the lines, including multiple arrowheads and arrowheads facing in multiple directions. There's an entire section in the \TikZ\ documentation that discusses arrow tips, including how to customize their shape and size. If you want to learn more, you'll have to read about it yourself.
\end{itemize}

\begin{center}
  \fbox{\includegraphics[width=0.75\linewidth]{img-11-7}}
\end{center}

When stringing multiple points together, you can specify how \TikZ\ draws the corners. A \texttt{mitre} creates sharp corners. And this is the default behavior. A \texttt{bevel} blunts the corners a bit by cutting them at an angle. Or you can use \texttt{round} corners. If you wanted an even rounder shape, you can use the \texttt{rounded corners} option. By picking different radii, you can make the corners more or less rounded.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-11-8}}
\end{center}

This is also where it pays to use \verb|cycle| instead of making the last point the same as the first point. This will ensure that the last corner is drawn appropriately.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-11-9}}
\end{center}

When connecting two points, we have only used the double dash to draw a straight line between them. Instead of connecting the two points directly, you may sometimes want to connect them using a combination of a horizontal and a vertical line. To do this, you simply replace the double dash with \verb$-|$ or \verb$|-$, depending on what direction you want to go first.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-11-10}}
\end{center}

If you are looking to connect two points with a curve instead of a line, you can use the \texttt{to} command instead of the double dash. And this will give you a couple more options.
\begin{itemize}
    \item If you are just trying to get a symmetric curve from one point to the next, you can use \texttt{bend left} or \texttt{bend right}. The left and right are relative to the straight line path, not describing the motion of the path. You can specify the size of the bend by specifying the angle. This angle is measured relative to the line connecting the two points, and the default value is 30 degrees.
    \item You can also specify the \texttt{out} and \texttt{in} angles for the curve. The angles used here are the standard position angles, so that 0 is pointing to the right. The \texttt{out} angle is the angle the curve leaves the initial point from, and the \texttt{in} angle is the angle the curve enters the terminal point at. This gives you even more control over the shape of the curve.
\end{itemize}

There are also three general transformations that can be applied to a wide range of \TikZ\ objects.
\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-11-11}}
\end{center}
\begin{itemize}
    \item Use \verb|shift| to translate objects both vertically and horizontally.
    \item Use \verb|xscale| and \verb|yscale| to scale the $x$ and $y$ dimensions separately, or use \verb|scale| to scale in both directions by the same amount.
    \item The \verb|rotate| command will rotate the image. It's important to note that this will rotate about the origin, not around some anchor point in the image.
\end{itemize}
These can be applied to a \verb|\draw| command, to a \texttt{node}, to a \texttt{circle} using the modern notation, and several other commands.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-11-12}}
\end{center}

These transformations are non-commutative, which means that the order you type them in will affect the outcome. \TikZ\ works from right to left, applying the transformation closest to the drawing commands first, as if this were a function notation.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-11-13}}
\end{center}

The last set of options for this video will be applied to nodes. We've already seen that we can do color fills. If we wanted to put a border around the node, we would add \texttt{draw} inside of the optional parameters for the node. You can adjust the thickness of the border by changing the \texttt{line width}. In fact, the line drawing commands for color, line style, and even line joining are all available as options for the border. If you change the color of the node, you will also change the color of the text unless you use the \verb|\textcolor{}{}| command inside of the node. There are other node shapes that you can use using the \texttt{shapes} tikzlibrary, and there's a \href{http://www.texample.net/tikz/examples/node-shapes/}{link to some examples} in the transcript.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-11-14}}
\end{center}

There are also some extra options for the placement of nodes along a path. The \verb|pos=val| command lets you specify where along the previous path you want to place the node. The value 0 corresponds to the first coordinate and the value 1 corresponds to the second coordinate. For the double dash and arcs, you can think of this as a linear progression.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-11-15}}
\end{center}

However, if you use the orthogonal paths, the value 0.5 corresponds to the corner, and so the speed along the two paths may not be equal. If you choose numbers outside of $[0,1]$, \LaTeX\ will extrapolate the position based on the path. Note that this does not work with the \texttt{to} command.

The contents of this video take care of most of what I do with \TikZ. It may not always be the most elegant solution, but it usually works. In the next video, we'll discuss some more about the things we can put into nodes, do a little bit of work with graphing, and introduce some more ideas that will probably be useful to know when working with \TikZ.